// TOWN SCRIPT
//    Town 1: Hatherond

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,j,k,r1,choice;

body;

beginstate INIT_STATE;
	set_name(6,"Rauling");
	set_name(24,"Offa");
	set_name(25,"Yse");
	set_name(26,"Herebeald");
	set_name(27,"Ingorn");
	set_name(28,"Seoran");
	set_name(29,"Eofenras");
	set_name(30,"Oslaf");
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// This state is called every turn the party is in this town.
break;

beginstate 10;
	if (get_flag(1,0) == 250)
		end();
	message_dialog("Catching a flicker of torchlight through a crack in the wall, you look for a secret door. Sure enough, you find one.",
	  "Behind is a small room, adorned with a single chair.");
	set_flag(1,0,250);
break;

beginstate 11;
	if (get_flag(100,0) < 1)
		set_state_continue(12);
	set_state_continue(15);
break;

beginstate 12;
	set_flag(100,0,1);
	set_state_continue(13);
break;

beginstate 13;
	reset_dialog();
	add_dialog_str(0,"Rauling stands. Putting his ear to the eastern wall, he listens for a minute, then turns to you. His face, you realize, has suddenly taken upon a much graver aspect, and his eyes hold you in complete attention.",0);
	add_dialog_str(1,"_It has been two decades since our people came from the eastern waters. It has been two decades that the Wolf and Falcon clans, each with twice our fields of territory, have held us back, depriving us of our own. Two decades.",0);
	add_dialog_str(2," But even with that, the Wolf and the Falcon do not sit in peace. They want us gone, erased forever from the chronicles of Ylmir, our very vestige washed from the land by the merciless ocean. That is what they want._ He pauses.",0);
	add_dialog_str(3,"_Or so it is said, and so we believe. But we have no proof. It is for that reason that you came here. You can blend into a crowd, and we cannot, for our complexions have not the same paleness as these native men.",0);
	add_dialog_str(4," We have reason to suspect that a caravan heading from here to northern Hengest carries a message for Scyld, master of the Falcon. We wish to have that message. And you will find and take it for us.",0);
	add_dialog_str(5," Ambush them in Ravenswood. Go with all the speed necessary. I have no more to say. Go._",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_state_continue(14);
break;

beginstate 14;
	message_dialog("_Good. Our hope lies upon you. Perhaps you wish to learn more of the seawyrm clan._","_By the way, here is a powerful magical item, only useful for travelling outdoors_.");
	reward_give(464);
break;

beginstate 15;
	if (get_flag(100,0) >= 2)
		set_state_continue(19);
	set_state_continue(16);
break;

beginstate 16;
	message_dialog("He sighs. _Finish your task as soon as possible. Do not tarry. Ambush the caravan in Ravenswood, take the message, and deliver it to me._","");
break;

beginstate 17;
	reset_dialog();
	add_dialog_str(0,"Rauling springs up when he sees you. Evidently he has heard of your deeds. _Give it to me! The papers! No... Yes. That._ He snatches it out of your hands and reads over them eagerly, then rereads them.",0);
	add_dialog_str(1,"Then he looks back up at you. _So it is then. Our suspicions are confirmed. But we need to know more._ He sits back down, and thinks for a while. His hands slide up and down the handles of the chair, gripping them rhythmically.",0);
	add_dialog_str(2,"At last, he speaks. _You will need to act as spies, since the others are occupied._ Others? You don't immediately catch his meaning, but listen on. _The masters of Hatherond, Aeschere and Finn, may speak of these things. Maybe..._",0);
	add_dialog_str(3,"He glances briefly at the floor. _Yes, that's it. If you can access the underground sewers, you might be able to surface in either of their quarters. Then it'll be up to luck. That's the hard part, but all great events must need some luck now and then.",0);
	add_dialog_str(4," You can reach the sewers from the inn. Go down there, and see where you can get to. Remember: stealth is of the essence. If you're found out... Well, do not be found out. Our success depends on yours._",0);
	add_dialog_str(5,"That being said, he turns back to his study of the papers.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	change_spec_item(0,-1);	
	set_state_continue(18);
break;

beginstate 18;
	message_dialog("He reads over the papers carefully, not sparing you a glance.","");
	set_flag(100,0,3);
break;

beginstate 19;
	if (get_flag(100,0) >= 3)
		set_state_continue(20);
	set_state_continue(17);
break;

beginstate 20;
	message_dialog("_Have you found out anything yet? No? Nothing? Well then, keep trying!_ He shakes his head.","");
break;

beginstate 21;
	block_entry(1);
	reset_dialog_preset_options(5);
	choice = run_dialog(0);
	if (choice == 2) {
		move_to_new_town(0,39,13);
		end();
		}
break;

beginstate 22;
	block_entry(1);
	reset_dialog_preset_options(5);
	choice = run_dialog(0);
	if (choice == 2) {
		move_to_new_town(0,40,37);
		end();
		}
break;

beginstate 23;
	if (get_flag(1,1) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"You have gained access to Aeschere's quarters. Richly decorated with wall tapestries, this place is almost a miniature palace. Perhaps he wouldn't mind you helping yourselves to some minor valuables.",0);
	add_dialog_str(1,"Still, there's a mission to be accomplished.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(1,1,250);
break;

beginstate 24;
	if (get_flag(100,0) >= 3)
		set_state_continue(25);
break;

beginstate 25;
	reset_dialog();
	add_dialog_str(0,"This wardrobe would provide a perfect hiding place were you to stalk here and eavesdrop on conversation in the building. Aeschere must have realized this: there's a miniscule hole in the wall, allowing a view of the room to the west.",0);
	add_dialog_str(1,"In this position, you could probably stay for a while and hope that you find out something before being found out.",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Wait.");
	choice = run_dialog(1);
	if (choice == 2)
		set_state_continue(28);
break;

beginstate 26;
	reset_dialog();
	add_dialog_str(0,"Time passes...",0);
	add_dialog_str(1,"Aeschere is still in the outside room, writing at his desk.",0);
	add_dialog_str(2,"The more you stay in this room, the better your chances of being found out. Still, it might be worth the risk.",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Wait.");
	choice = run_dialog(1);
	if (choice == 2)
		set_state_continue(29);
break;

beginstate 27;
	reset_dialog();
	add_dialog_str(0,"Time passes...",0);
	add_dialog_str(1,"Aeschere pauses abruptly in his writing, and glances up. He furrows his brow and looks around the room carefully, his eyes halting straight at yours. Frozen in position, you can only remain stationary.",0);
	add_dialog_str(2,"He suddenly turns his gaze away. You hear the opening of a door, and someone else coming into the room, followed by a brief greeting. The speaker is aged, by the sound of his voice, and none too happy.",0);
	add_dialog_str(3,"_Hail!_ counters Aeschere. _The harbour master does not frequent this hall. What brings your lordship to my humble domain?_",0);
	add_dialog_str(4,"_Do not bandy words with me, Aeschere. These are troublesome days, though you may think it not so._ The speaker walks into sight, a tall, grey-clad man, elderly, though it is difficult to gauge his age from this perspective.",0);
	add_dialog_str(5,"He takes a seat in front of the desk. _Our message to Scyld has not been replied to. He is not wont to stay his silence. I must say that either the Falcon or the Seawyrm has turned against us._",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_state_continue(30);
break;

beginstate 28;
	play_sound(20);
	set_state_continue(26);
break;

beginstate 29;
	play_sound(20);
	set_state_continue(27);
break;

beginstate 30;
	reset_dialog();
	add_dialog_str(0,"Aeschere shrugs. _More likely some brigands took them, I presume. Your lordship makes too much of it. If need be, the message can be sent again with more guard._",0);
	add_dialog_str(1,"_Caution is of the imperative,_ answers the grey-clad speaker. A pause. _And of that note, pray tell - who spies upon our discourse?_",0);
	add_dialog_str(2,"Aeschere laughs. _Can nothing escape your notice? A few unwanted houseguests, who are now on an unpleasant downward journey._",0);
	add_dialog_str(3,"The floor opens beneath you. It's a long fall...",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_state_continue(33);
break;

beginstate 31;
	if (is_combat() == 1) 
		end();
	set_state_continue(24);
break;

beginstate 32;
	block_entry(1);
		move_to_new_town(3,41,6);
		end();
break;

beginstate 33;
	i = 0;
	while (i < 6) {
			r1 = get_ran(6,1,5);
			damage_char(i,r1,4);
		i = i + 1;
		}
	set_state_continue(35);
break;

beginstate 34;
	message_dialog("Over the center of the city flies a white flag emblazoned with the image of a grey, menacing wolf.","");
	block_entry(1);
break;

beginstate 35;
	set_flag(100,0,4);
	set_state_continue(32);
break;

beginstate 37;
	run_scenario_script(13);
break;

beginstate 40;
	reset_dialog();
	add_dialog_str(0,"A small note lies on the chair:",0);
	add_dialog_str(1,"AGENTS -",0);
	add_dialog_str(2,"Report immediately to Ingusi at the southeasternmost region of the isle, and ascend the tower.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
break;

beginstate 44;
	if (get_flag(100,0) >= 4)
		set_state_continue(40);
break;

beginstate 45;
	if (get_flag(100,0) >= 4)
		set_state_continue(46);
break;

beginstate 46;
	if (get_flag(46,1) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"Aeschere still sits at his desk, evidently untroubled by your presence. In fact, he doesn't appear to even notice you. If he's worried at all, he's not making any show of it.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(46,1,250);
break;

beginstate 47;
        if (char_has_trait(0,22) == 1)
		end();
	set_state_continue(48);
break;

beginstate 48;
	message_dialog("Upon closer inspection, it becomes clear that the book describes a powerful and draining magical meditation which enables you to disrupt evil magic in an altar or other cursed location.","(The Ritual of Sanctification is an ability that can be used once a day near altars and other objects with evil enchantments. If you do so, interesting things may happen. You will forget the Ritual when you leave the scenario.)");
	set_char_trait(0,22,1);
	set_char_trait(1,22,1);
	set_char_trait(2,22,1);
	set_char_trait(3,22,1);
break;

